<?php
use app\assets\AppAsset;
use yii\helpers\Url;
AppAsset::register($this);
$this->registerJSFile('@web/js/readcum.js',['depends'=>['app\assets\AppAsset']]);
$this->registerJSFile('@web/js/time.js',['depends'=>['app\assets\AppAsset']]);
$this->registerJSFile('@web/js/getKey.js',['depends'=>['app\assets\AppAsset']]);
$this->registerJSFile('@web/js/hotvoice.js',['depends'=>['app\assets\AppAsset']]);
$this->registerCssFile('@web/css/sqread.css',['depends'=>['app\assets\AppAsset']]);

$options=[];
foreach ($read_option as $a) $options[$a['options']]=$a['content'];
$arr=str_split($read_question[$que-2]['answer']);
if(strstr($read_question[$que-2]['answer'],','))//表格题
{
    $correct_answer=json_decode($read_question[$que-2]['answer']);
}else
foreach ($arr as $i=>$item)
    $correct_answer[$i]=ord($item)-65;
$this->title="Reading";
?>
<script type="text/javascript">
    <?php
    $session = \Yii::$app->session;
    $session->open();
    ?>
    var current_userid=<?=$session['user_id'];?>;
	var que_info={
		class1:'<?=$read_content['class1_id'];?>',
		class2:'<?=$read_content['class2_id'];?>',
		question:'<?=$read_question[$que-2]['id'];?>',
		tnum:'<?=$read_content['class_num'];?>'
		
	};
    window.onload=function(){
        var Arr=[<?php if($show_ans) foreach ($user_key as $item){if(isset($item))foreach ($item as $value)echo "'".$value."',";}?>];
        for (var i = 0; i < Arr.length; i++) {
            var id=Change(Arr[i]);
            if ($(id).hasClass("the-key-line")) {
                $(id).addClass("right-line");
            }else{
                $(id).addClass("user-key");
            }
        }
        <?php if($show_ans){?>
        $('#cost-time').html(secToMin(<?=$t_time[$que-1];?>));
        <?php }else{?>
        $('.the-key-line').removeClass("the-key-line");
        <?php }?>
        function Change(val){
            return '#'+val+'';
        }
        getKey('#paragraph<?=$read_question[$que-2]['paragraph'];?>');

    }
</script>
<form action="?r=community/<?=$action;?>" id="nextque" method="post">
	<input type="hidden" name="que" value="<?=$que;?>">
	<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
</form>
<div class="container">
	<div class="total-info clearfix">
		<span class="tpo-info pull-left"><?=strtoupper($class2_name);?>-<?=$read_content['class_num'];?> Question <?=$read_question[$que-2]['tnum'];?></span>
		<span class="li-next pull-right" id="next">next <i class="fa fa-angle-double-right"></i></span>
		<ul class="list-unstyled list-inline pull-right page-list">
            <?php
            for($i=1;$i<=$read_question_num;$i++)
            {
                $result="";
                $classes="";
                if($show_ans)
                {
                    if(strstr($read_question[$i - 1]['answer'],','))//表格题
                    {
                        $result =json_encode($answer[$i]);
                    }else
                    {
                        foreach ($answer[$i] as $j => $value)
                            if ($value == 2)
                                $result .= chr($j + 65);
                    }
                    if ($result == $read_question[$i - 1]['answer'])
                        $classes .= "ans-right";
                    else
                        $classes .= "ans-wrong";
                }
                if ($i == $que - 1)
                    $classes .= " ans-current";
                ?>
                <li id="que_num<?=$i;?>" class="<?=$classes;?>"><?=$i;?></li>
                <?php
            }
            ?>
		</ul>
	</div>
	<div class="total-part">
		<div class="total-lead clearfix">
			<span class="top-que pull-left"><?=strtoupper($class2_name);?>-<?=$read_content['class_num'];?> Question<?=$read_question[$que-2]['tnum'];?></span>
            <?php if($show_ans){?>
            <span class="time pull-left">题目耗时:<span id="cost-time">00:00</span></span>
			<span class="repeat-doit pull-right"><i class="fa fa-rotate-left"></i>&nbsp;&nbsp;<a href="<?=Url::to('@web/?r=reading/index&id='.$read_content['id']);?>">重做本篇</a></span>
            <?php }?>
        </div>
		<div class="main-part clearfix">
			<div class="col-xs-5 users">
				<div class="question">
					<p class="que-self">
						<?=$read_question[$que-2]['content'];?>
					</p>
					<div class="table-A">
						<span class="col-xs-2 table-text">table A:</span>
						<ul class="col-xs-10 table-space">
                            <?php
                            if($show_ans)
                            {
                                foreach ($correct_answer as $i =>$item)
                                {
                                    if($item=='1')
                                    {
                                        ?><li class="col-xs-4"><?=chr($i+65)?></li>
                                <?php
                                    }
                                }
                            }else for($i=0;$i<3;$i++) { ?>
                                <li class="col-xs-4"></li>
                                <?php
                            }
                            ?>
						</ul>
					</div>
					<div class="table-B">
						<span class="col-xs-2 table-text">table B:</span>
						<ul class="col-xs-10 table-space">
                            <?php
                            if($show_ans)
                            {
                                foreach ($correct_answer as $i =>$item)
                                {
                                    if($item=='2')
                                    {
                                        ?><li class="col-xs-4"><?=chr($i+65)?></li>
                                        <?php
                                    }
                                }
                            }else for($i=0;$i<2;$i++) { ?>
                                <li class="col-xs-4"></li>
                                <?php
                            }
                            ?>
						</ul>
					</div>
					<div class="steps clearfix">
						<div class="step-three-info read-ano another-step pull-left">
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[0]!=3)echo"isright";if($answer[$que-1][0]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[A]</span>
								<span class="que-text que-kinds">
									<?=$options['A'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[1]!=3)echo"isright";if($answer[$que-1][1]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[B]</span>
								<span class="que-text que-kinds">
									<?=$options['B'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[2]!=3)echo"isright";if($answer[$que-1][2]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[C]</span>
								<span class="que-text que-kinds">
									<?=$options['C'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[3]!=3)echo"isright";if($answer[$que-1][3]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[D]</span>
								<span class="que-text que-kinds">
									<?=$options['D'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[4]!=3)echo"isright";if($answer[$que-1][4]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[E]</span>
								<span class="que-text que-kinds">
									<?=$options['E'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[5]!=3)echo"isright";if($answer[$que-1][5]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[F]</span>
								<span class="que-text que-kinds">
									<?=$options['F'];?>
								</span>
							</div>
							<div class="que-ans clearfix">
								<span class="ans-op pull-left <?php if($show_ans){ if ($correct_answer[6]!=3)echo"isright";if($answer[$que-1][6]<=2)echo" isuser";}?>"><i class="fa fa-check"></i></span>
								<span class="ans-select another-select pull-left">[G]</span>
								<span class="que-text que-kinds">
									<?=$options['G'];?>
								</span>
							</div>
						</div>
					</div>
                    <?php
                    if($show_ans) {
                        ?>
                        <div class="correct-ans">
                            正确答案: <span class="table-text">table A:&nbsp;&nbsp;</span><span
                                class="cor-real-ans"><?php foreach ($correct_answer as $i => $item) if ($item == '1') echo chr($i + 65); ?></span>&nbsp;&nbsp;&nbsp;&nbsp;<span
                                class="table-text">table B:&nbsp;&nbsp;</span><span
                                class="cor-real-ans"><?php foreach ($correct_answer as $i => $item) if ($item == '2') echo chr($i + 65); ?></span>
                        </div>
                        <div class="user-ans">
                            我的答案: <span class="table-text">table A:&nbsp;&nbsp;</span><span
                                class="user-real-ans"><?php foreach ($answer[$que - 1] as $i => $item) if ($item == '1') echo chr($i + 65); ?></span>&nbsp;&nbsp;&nbsp;&nbsp;<span
                                class="table-text">table B:&nbsp;&nbsp;</span><span
                                class="user-real-ans"><?php foreach ($answer[$que - 1] as $i => $item) if ($item == '2') echo chr($i + 65); ?></span>
                        </div>
                        <?php
                    }
                    ?>
				</div>
				<div class="hot-voice">
					<div class="hot-lead"><i class="fa fa-fire"></i>&nbsp;&nbsp;热门声音</div>
					<div class="add-more">
						<span>加载更多</span><span id="loadgif" class="hidden"><img src="<?=Url::to('@web/images/addmore.gif');?>"></span>
					</div>
				</div>
                <?php if($show_ans){?>
				<div class="user-gain clearfix">
					<div class="my-record">
						<span>我的题解</span>
					</div>
					<div class="record-text pull-left">
						<div id="user-comments" contenteditable="true"></div>
					</div>
					<div class="share pull-right">
						分享 <span>Share</span>
					</div>
					<div id="comment-succeed">
						<img src="<?=Url::to('@web/images/updating.gif');?>" alt="上传中...">
						<span>updating...</span>
					</div>
				</div>
                <?php }?>
			</div>
			<div class="col-xs-7 ques">
				<div class="listen-text">
					<div class="text-wrap">
						<p class="text-title"><?=$read_content['title'];?></p>
						<span class="text-main">
							<?=$read_content['content'];?>
						</span>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div id="voicemodel" class="hidden">
	<div class="user-lead clearfix">
		<div class="user-info pull-left clearfix">
			<div class="user-pic pull-left">
				<img src="<?=Url::to('@web/images/timg.jpg');?>">
			</div>
			<div class="user-id-date pull-left">
				<span class="user-id"></span><br>
				<span class="user-date"></span>
			</div>
		</div>
		<div class="good-times pull-right" title="点赞量">
			<span><i class="fa fa-thumbs-o-up"></i>&nbsp;&nbsp;<span class="goods"></span></span>
		</div>
		<div class="view-times pull-right" title="浏览量">
			<span><i class="fa fa-eye"></i>&nbsp;&nbsp;<span class="views"></span></span>
		</div>
	</div>
	<div class="user-comments"></div>
	<div class="view-all center-block">点击查看全文</div>
</div>